<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/MF93FL27/modconf.mex");
MYTCONN(); 	
	if ($_POST['bss_Office'] > 0) {
	$qr_o = 'AND bss_Office = '.$_POST['bss_Office'];
	
	} 
	if ($_POST['bss_Product'] > 0) {
	$qr_p = 'AND bss_Product = '.$_POST['bss_Product'];
	
	}
  $Results = $GLOBALS['MYT']->db_array("SELECT bss_ID AS OID, 
  	InternalRef AS COL1,
	NAME AS COL2,
	bss_Time AS COL3, 
	OriNombre AS COL4, 
	stt_Word AS COL5, 
	bss_IniQuant AS COL6, 
	bss_CrrQuant AS COL7
  FROM bonusproducts
  LEFT OUTER JOIN bonus_productstocks ON REF = bss_Product
  INNER JOIN hd_sysstatus ON stt_Sistema = 22 AND sttFlag = bss_Status
  INNER JOIN origenes ON bss_Office = OriNumero
  WHERE bss_Office > 0 {$qr_o} {$qr_p}");
	$CARD = $Results[0]; ?> 
<script charset="utf-8" type="text/javascript">
Ext.onReady(function(){

    Ext.QuickTips.init();

    var myData = [
	<?php   
	for ($i=1;$i<=$CARD;$i++) { 
	echo '['.$i.','.$Results[$i]['OID'].',\''.$Results[$i]['COL1'].'\',\''.$Results[$i]['COL2'].'\',\''.$Results[$i]['COL3'].'\',\''.$Results[$i]['COL4'].'\',\''.$Results[$i]['COL5'].'\',\''.$Results[$i]['COL6'].'\',\''.$Results[$i]['COL7'].'\']';
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'OID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
			   {name: 'COL4', type: 'string'},
               {name: 'COL5', type: 'string'},
               {name: 'COL6', type: 'string'},
               {name: 'COL7', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Entrega", width: 80, sortable: true, locked:true, dataIndex: 'OID'},
        {header: "Referencia", width: 80, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Produto", width: 150, sortable: true, dataIndex: 'COL2'},
        {header: "Data", width: 120, sortable: true, locked:true, align: 'right', dataIndex: 'COL3'},
        {header: "Loja", width: 200, sortable: true, locked:true, dataIndex: 'COL4'},
        {header: "Estado", width: 80, sortable: true, locked:true, align: 'right',dataIndex: 'COL5'},
        {header: "Quantidade", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'COL6'},
        {header: "Disponivel", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'COL7'}
    ]);

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
		ds: ds,
		cm: colModel,
		sm: selmode,
			listeners: {
	 				rowdblclick: function(ds, row) { 
					var record = ds.getStore().getAt(row);
  					var value = record.get('OID');	
					modalwindow('Confirmar','<?php echo $MODURL;?>lib/stk_dstentry.mex?RSID='+value,600,400);
				}
			},
	    height: 420,
        renderTo: 'bss_stockresults'
    });
		
});
</script>